package t25519;

import java.util.Map;

public class TestMap {

        // 1添加员工
        public void addEmp(Map<String, Emp> empMap, Emp emp) {
            empMap.put(emp.getNumber(), emp);
        }

        // 2查询所有员工
        public void findAllEmp(Map<String, Emp> empMap) {
            if (empMap.isEmpty()) {
                System.out.println("员工列表为空");
            } else {
                empMap.forEach((key, value) -> System.out.println(value));
            }
        }

        // 3根据姓名查询员工
        public void findEmpByName(Map<String, Emp> empMap, String name) {
            boolean found = false;
            for (Emp emp : empMap.values()) {
                if (emp.getName().equals(name)) {
                    System.out.println(emp);
                    found = true;
                }
            }
            if (!found) {
                System.out.println("未找到姓名为 " + name + " 的员工");
            }
        }

        // 4根据编号删除员工
        public void deleteEmp(Map<String, Emp> empMap, String number) {
            Emp removedEmp = empMap.remove(number);
            if (removedEmp != null) {
                System.out.println("成功删除员工：" + removedEmp);
            } else {
                System.out.println("未找到编号为 " + number + " 的员工");
            }
        }

        // 5根据编号查询员工
        public Emp findEmpByNumber(Map<String, Emp> empMap, String number) {
            return empMap.get(number);
        }

        // 6根据编号改年龄
        public void updateEmp(Map<String, Emp> empMap, Emp emp) {
            empMap.put(emp.getNumber(), emp);
        }
    }

